/**
 * 评论组件
 * @params datasets 数据
 */
export function commentFormat(datasets) {
  let seriesData = [];
  const { type, source, dimensions, fieldNameChainMap } = datasets;
  if (type === 'STATIC') {
    seriesData = source;
  }
  else{
    const { yAxisTitle, yAxisHide, yAxisComment , yAxisDate} = dimensions;
    const yAxisCommentArr = yAxisComment.split('&');
    seriesData = source.map((item) => {
      const contentList =  getcontent(yAxisCommentArr, item);
      const data = {
        title: item[yAxisTitle],
        date: item[yAxisDate],
        value: item[yAxisHide],
        content: contentList,
        filedMap: {
          [fieldNameChainMap?.yAxisTitle ? fieldNameChainMap?.yAxisTitle[yAxisTitle] : '' ]: item[yAxisTitle],
          [fieldNameChainMap?.yAxisDate ? fieldNameChainMap?.yAxisDate[yAxisDate] : '' ] : item[yAxisDate],
          [fieldNameChainMap?.yAxisHide ? fieldNameChainMap?.yAxisHide[yAxisHide] : '' ]: item[yAxisHide],
        },
      }
      //处理评论内容是多个维度
      yAxisCommentArr.forEach((item,index) =>{
        data.filedMap[fieldNameChainMap?.yAxisComment? fieldNameChainMap?.yAxisComment[item] : ''] = contentList[index]
      })
      return data;
    });
  }
  return {
    seriesData,
  };
}
//多个评论内容
function getcontent(yAxisComment,item) {
  return yAxisComment.map((key)=>{
      return item[key];
  });
}